package ua.kpi_java_training.tyshchenko.module1;

import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests for Palindrom.class
 *
 * @version 1.1 26 May 2013
 * @author Vlad Tyshchenko
 */
public class PalindromTest {
    Palindrom testPal = new Palindrom();

    @Before
    public void setUp() {
        testPal.line = "asdGEREGEndfBNMMNB";
    }

    @Test
    public void testGetPalindromOneCenterSymbol() {
        Assert.assertEquals("one centre symbol, 2 iteration", testPal.getPalindromOneCenterSymbol(5, 2), "GEREG");
        Assert.assertEquals("one centre symbol, 1 iteration", testPal.getPalindromOneCenterSymbol(5, 1), "ERE");
        Assert.assertEquals("one centre symbol, 0 iteration", testPal.getPalindromOneCenterSymbol(8, 1), null);
    }

    @Test
    public void testGetPalindromTwoCenterSymbol() {
        Assert.assertEquals("two centre symbol, 1 iteration", testPal.getPalindromTwoCenterSymbol(14, 1), "NMMN");
        Assert.assertEquals("two centre symbol, 2 iteration", testPal.getPalindromTwoCenterSymbol(14, 2), "BNMMNB");
        Assert.assertEquals("two centre symbol, 0 iteration", testPal.getPalindromTwoCenterSymbol(5, 2), null);
    }

    @Test
    public void testSearchPalindrom() {
        testPal.searchPalindrom(5);
        Assert.assertEquals("two palindroms must be found", testPal.palindroms, ("ERE" + "\n" + "GEREG" + "\n"));
        testPal.palindroms = "";
        testPal.searchPalindrom(9);
        Assert.assertEquals("palindroms mustn't be found", testPal.palindroms, "");
    }

    @Test
    public void testEnumerationLine() {
        testPal.enumerationLine();
        Assert.assertEquals(" All palindroms in line", testPal.palindroms,
                ("ERE" + "\n" + "GEREG" + "\n" + "EGE" + "\n" + "NMMN" + "\n" + "BNMMNB" + "\n"));
    }
}